﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.facebook.delegates {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import com.facebook.net.*;
    import flash.net.*;
    import com.facebook.session.*;
    import com.adobe.images.*;
    import com.facebook.utils.*;
    import com.facebook.commands.photos.*;

    public class WebImageUploadDelegate extends AbstractFileUploadDelegate {

        public function WebImageUploadDelegate(_arg1:FacebookCall, _arg2:WebSession){
            super(_arg1, _arg2);
        }
        override protected function getExt():String{
            return ((((call as IUploadPhoto).uploadType == UploadPhotoTypes.JPEG)) ? "jpeg" : "png");
        }
        override protected function getContentType():String{
            return ("Content-Type: image/jpg");
        }
        override protected function sendRequest():void{
            var _local1:ByteArray;
            var _local4:JPGEncoder;
            var _local2:URLRequest = new URLRequest(_session.rest_url);
            var _local3:Object = call.args.data;
            if (_local3 == null){
                super.sendRequest();
                return;
            };
            if ((((PlayerUtils.majorVersion == 9)) && ((_local3 is FileReference)))){
                throw (new TypeError("Uploading FileReference with Player 9 is unsupported.  Use either an BitmapData or ByteArray."));
            };
            if ((_local3 is Bitmap)){
                _local3 = (_local3 as Bitmap).bitmapData;
            };
            if ((((PlayerUtils.majorVersion == 10)) && ((_local3 is FileReference)))){
                _local1 = (_local3 as FileReference)["load"]();
                fileRef = (_local3 as FileReference);
                fileRef.addEventListener(Event.COMPLETE, onFileRefComplete);
            } else {
                if ((_local3 is ByteArray)){
                    uploadByteArray((_local3 as ByteArray));
                } else {
                    if ((_local3 is BitmapData)){
                        switch ((call as UploadPhoto).uploadType){
                            case UploadPhotoTypes.JPEG:
                                _local4 = new JPGEncoder((call as UploadPhoto).uploadQuality);
                                ba = _local4.encode((_local3 as BitmapData));
                                break;
                            case UploadPhotoTypes.PNG:
                                ba = PNGEncoder.encode((_local3 as BitmapData));
                                break;
                        };
                        uploadByteArray(ba);
                    } else {
                        throw (new Error((("Error data type " + call.args.data) + " is not supported.  Please use one of the following types:  FileReference, ByteArray, BitmapData or Bitmap.")));
                    };
                };
            };
        }

    }
}//package com.facebook.delegates 
